package gui;

import javax.swing.*;
import javax.swing.table.*;

import java.awt.*;
import java.sql.*;
import java.util.Vector;

import database.DailyOrderOperations;

@SuppressWarnings("serial")
public class day1 extends JPanel {

	private JPanel p1;
	private DefaultTableModel model;
	private JTable table;
	private ResultSet rs;
	private int day;
	public day1(int day) {
		this.day = day;
		this.setPreferredSize(new Dimension(700, 280));
		
		//panel 1
		p1 = new JPanel();
		p1.setPreferredSize(new Dimension(695, 295));
		
		// create JTable
		String[] cols={"Supplier","Product","Quantity"};
		int numRows=100;
		model = new DefaultTableModel(numRows,cols.length);
		model.setColumnIdentifiers(cols);
		table = new JTable(model);
		table.setFillsViewportHeight(true);
		table.setAutoCreateColumnsFromModel(false);
		JScrollPane sp=new JScrollPane(table);
		sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		sp.setPreferredSize(new Dimension(695, 260));
		model.setRowCount(0);
		
		//adjust size of columns on table
		TableColumnModel tbm=table.getColumnModel();
		tbm.getColumn(2).setMaxWidth(70);
		model.setRowCount(0);
		
		p1.add(sp,BorderLayout.CENTER);
		add(p1);
		loadTable();
	}
	DailyOrderOperations doo = new DailyOrderOperations();
		@SuppressWarnings({ "rawtypes", "unchecked" })
		public void loadTable() 
		{
			rs = doo.fillTable(day);
			int counter = 0;
			model.setRowCount(0);
			try {
				while(rs.next()){
					Vector row = new Vector();
					row.add(rs.getString(1));
					row.add(rs.getString(2));
					row.add(rs.getInt(3));
					model.insertRow(counter,row);
					counter++;
				}
			} 
			catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		public static void main(String args[]) {
			MainScreen ms = new MainScreen();
			ms.setVisible(true);
		}
}





	
	